#include "stdafx.h"
#include <winuser.h>
#include <WindowsX.h>
#include "UIFrame.h"
#include "UIRect.h"
#include "UICaptionButton.h"
#include "UINcFrame.h"
#include "UIGridImgPlus.h"
#include "UIMemWindowDC.h"
#include "UIMemClientDC.h"
#include "UIWindowDC.h"
#include "UIGlobalStyle.h"
#include "UIClip.h"
#include "UIMenu.h"
#include "UIDrawTool.h"
#include "UIMemDC.h"

CUIFrame::CUIFrame( HWND hWnd ): CUIWindowBase( hWnd ), m_bFrameActive( FALSE ), m_pPopupMenu( NULL )
    , m_pPressCapBtn( NULL ), m_pHotCapBtn( NULL ), m_pFrameBK( NULL ), m_pClose( NULL ), m_pMax( NULL ), m_pMin( NULL )
{
    m_iFrameWidth =::GetSystemMetrics( SM_CXFRAME );
    m_iFrameHeight =::GetSystemMetrics( SM_CYFRAME );
    m_iFrameBorderWidth =::GetSystemMetrics( SM_CXBORDER );
    m_iFrameBorderHeight =::GetSystemMetrics( SM_CYBORDER );
    m_iFrameCaptionHeight =::GetSystemMetrics( SM_CYCAPTION );
    m_iOldCapHeight = m_iFrameCaptionHeight;
}

CUIFrame::~CUIFrame()
{
    RemoveFrameBorder();
    RemoveSysCapButton();
}

void CUIFrame::ReDrawFrame()
{
    RECT rcClient;
    ::GetWindowRect( GetHwnd(), &rcClient );

    SetWindowPos( GetHwnd(), NULL, rcClient.left, rcClient.top,
                  rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_FRAMECHANGED );

}

void CUIFrame::SetFrameMargin( int iLeft, int iTop, int iRight, int iBottom )
{
    if ( 0 < iTop )
    {
        m_iOldCapHeight = m_iFrameCaptionHeight;
        m_iFrameCaptionHeight = iTop;
    }

    ReDrawFrame();
}

void CUIFrame::AddCaptionButton( CUICaptionButton* pCapBtn )
{
    if ( NULL != pCapBtn )
    {
        m_vecCapBtn.push_back( pCapBtn );
    }
}

void CUIFrame::SetCloseBtnImg( LPCTSTR lpszImg, IMGDIRECTION imgdir/* =IMG_HOR */, UINT imgCount/* =1 */ )
{
    RECT rcWnd;
    ::GetWindowRect( GetHwnd(), &rcWnd );

    ::EnableMenuItem( ::GetSystemMenu( GetHwnd(), FALSE ), SC_CLOSE, MF_DISABLED );
    m_pClose = new CUICaptionButton( GetHwnd(), SYS_BTN_CLOSE, lpszImg, imgdir, imgCount, HTCLOSE );
    m_pClose->SetPosition( rcWnd.right - rcWnd.left - m_pClose->GetSize().cx - 5, 10 );
    AddCaptionButton( m_pClose );
}

void CUIFrame::SetMaxBtnImg( LPCTSTR lpszImg, IMGDIRECTION imgdir/* =IMG_HOR */, UINT imgCount/* =1 */ )
{
    RECT rcWnd;
    ::GetWindowRect( GetHwnd(), &rcWnd );

    if ( WS_MAXIMIZEBOX == ( GetStyle() & WS_MAXIMIZEBOX ) )
    {
        ::SetWindowLong( GetHwnd(), GWL_STYLE, GetStyle() & ~WS_MAXIMIZEBOX );
        m_pMax = new CUICaptionButton( GetHwnd(), SYS_BTN_RESTORE, lpszImg, imgdir, imgCount, HTMAXBUTTON );
        m_pMax->SetPosition( m_pClose->GetBorder().left - m_pMax->GetSize().cx, 10 );
        AddCaptionButton( m_pMax );
    }
}

void CUIFrame::SetMinBtnImg( LPCTSTR lpszImg, IMGDIRECTION imgdir/* =IMG_HOR */, UINT imgCount/* =1 */ )
{
    RECT rcWnd;
    ::GetWindowRect( GetHwnd(), &rcWnd );

    if ( WS_MINIMIZEBOX == ( GetStyle() & WS_MINIMIZEBOX ) )
    {
        ::SetWindowLong( GetHwnd(), GWL_STYLE, GetStyle() & ~WS_MINIMIZEBOX );
        m_pMin = new CUICaptionButton( GetHwnd(), SYS_BTN_MIN, lpszImg, imgdir, imgCount, HTMINBUTTON );
        m_pMin->SetPosition( m_pMax->GetBorder().left - m_pMin->GetSize().cx, 10 );
        AddCaptionButton( m_pMin );
    }
}

void CUIFrame::RemoveSysCapButton()
{
    vector<CUICaptionButton*>::const_iterator cit = m_vecCapBtn.begin();

    for ( cit; cit != m_vecCapBtn.end(); cit++ )
    {
        CUICaptionButton* pCapbtn = *cit;

        if ( NULL != pCapbtn )
        {
            delete pCapbtn;
            pCapbtn = NULL;
        }

        m_vecCapBtn.erase( cit );
    }

    m_vecCapBtn.clear();
}

void CUIFrame::SetFrameCaptionImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount )
{
    RECT rcClient, rcWnd;
    ::GetClientRect( GetHwnd(), &rcClient );
    ::GetWindowRect( GetHwnd(), &rcWnd );

    m_pFrameCaption = new CUIGridImgPlus();
    m_pFrameCaption->LoadImg( lpszImg, imgdir, imgCount );
    m_pFrameCaption->SetPosition( 0, 0 );
    m_pFrameCaption->SetSize( rcWnd.right - rcWnd.left, m_iFrameBorderHeight + m_iFrameHeight + m_iFrameCaptionHeight );
    RECT rcMargin;
    ::SetRect( &rcMargin, 10, 15, 10, 0 );
    m_pFrameCaption->SetMargin( rcMargin );
}

void CUIFrame::SetFrameLeftImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount )
{
    RECT rcClient, rcWnd;
    ::GetClientRect( GetHwnd(), &rcClient );
    ::GetWindowRect( GetHwnd(), &rcWnd );

    m_pFrameLeft = new CUIGridImgPlus();
    m_pFrameLeft->LoadImg( lpszImg, imgdir, imgCount );
    m_pFrameLeft->SetPosition( 0, m_iFrameBorderHeight + m_iFrameHeight + m_iFrameCaptionHeight );
    m_pFrameLeft->SetSize( m_iFrameBorderWidth + m_iFrameWidth, rcWnd.bottom - rcWnd.top - m_iFrameHeight - m_iFrameBorderHeight );
    RECT rcMargin;
    ::SetRect( &rcMargin, m_iFrameBorderWidth + m_iFrameWidth, 0, 0, 0 );
    m_pFrameLeft->SetMargin( rcMargin );
}

void CUIFrame::SetFrameRightImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount )
{
    RECT rcClient, rcWnd;
    ::GetClientRect( GetHwnd(), &rcClient );
    ::GetWindowRect( GetHwnd(), &rcWnd );

    m_pFrameRight = new CUIGridImgPlus();
    m_pFrameRight->LoadImg( lpszImg, imgdir, imgCount );
    m_pFrameRight->SetPosition( rcWnd.right - rcWnd.left - m_iFrameBorderWidth - m_iFrameWidth, m_iFrameBorderHeight + m_iFrameHeight + m_iFrameCaptionHeight );
    m_pFrameRight->SetSize( m_iFrameBorderWidth + m_iFrameWidth, rcWnd.bottom - rcWnd.top - m_iFrameHeight - m_iFrameBorderHeight );
    RECT rcMargin;
    ::SetRect( &rcMargin, 0, 0, m_iFrameBorderWidth + m_iFrameWidth, 0 );
    m_pFrameRight->SetMargin( rcMargin );
}

void CUIFrame::SetFrameBottomImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount )
{
    RECT rcClient, rcWnd;
    ::GetClientRect( GetHwnd(), &rcClient );
    ::GetWindowRect( GetHwnd(), &rcWnd );

    m_pFrameBottom = new CUIGridImgPlus();
    m_pFrameBottom->LoadImg( lpszImg, imgdir, imgCount );
    m_pFrameBottom->SetPosition( 0, rcWnd.bottom - rcWnd.top - m_iFrameBorderHeight - m_iFrameHeight );
    m_pFrameBottom->SetSize( rcWnd.right - rcWnd.left, m_iFrameBorderHeight + m_iFrameHeight );
    RECT rcMargin;
    ::SetRect( &rcMargin, 5, 5, 5, 5 );
    m_pFrameBottom->SetMargin( rcMargin );
}

void CUIFrame::SetFrameBkImg( LPCTSTR lpszImg, IMGDIRECTION imgdir, UINT imgCount )
{
    RECT rcClient;
    ::GetClientRect( GetHwnd(), &rcClient );

    m_pFrameBK = new CUIGridImgPlus();
    m_pFrameBK->LoadImg( lpszImg, imgdir, imgCount );
    m_pFrameBK->SetPosition( 0, 0 );
    m_pFrameBK->SetSize( rcClient.right - rcClient.left, rcClient.bottom - rcClient.top );
    RECT rcMargin;
    ::SetRect( &rcMargin, 0, 0, 0, 0 );
    m_pFrameBK->SetMargin( rcMargin );
}

void CUIFrame::RemoveFrameBorder()
{
    if ( NULL != m_pFrameCaption )
    {
        delete m_pFrameCaption;
        m_pFrameCaption = NULL;
    }

    if ( NULL != m_pFrameLeft )
    {
        delete m_pFrameLeft;
        m_pFrameLeft = NULL;
    }

    if ( NULL != m_pFrameRight )
    {
        delete m_pFrameRight;
        m_pFrameRight = NULL;
    }

    if ( NULL != m_pFrameBottom )
    {
        delete m_pFrameBottom;
        m_pFrameBottom = NULL;
    }

    if ( NULL != m_pFrameBK )
    {
        delete m_pFrameBK;
        m_pFrameBK = NULL;
    }
}

LRESULT CUIFrame::OnNcPaint()
{
    CUIWindowDC dcWnd( GetHwnd() );

    RECT rcWnd;
    ::GetWindowRect( GetHwnd(), &rcWnd );
    ::OffsetRect( &rcWnd, -rcWnd.left, -rcWnd.top );

    CUIWindowDC dc( GetHwnd() );
    dc.ExcludeClient( GetHwnd() );

    m_pFrameCaption->Draw( dc.GetDC() );

    m_pFrameLeft->Draw( dc.GetDC() );

    m_pFrameRight->Draw( dc.GetDC() );

    m_pFrameBottom->Draw( dc.GetDC() );

    vector<CUICaptionButton*>::const_iterator cit = m_vecCapBtn.begin();

    for ( cit; cit != m_vecCapBtn.end(); cit++ )
    {
        CUICaptionButton* pCapbtn = *cit;
        pCapbtn->Draw( dc.GetDC() );
    }

    return 0;
}

LRESULT CUIFrame::OnNcHitTest( WPARAM wParam, LPARAM lParam, LRESULT lRet )
{
    LRESULT hitCode = lRet;

    POINT ptCursor;
    ptCursor.x = GET_X_LPARAM( lParam );
    ptCursor.y = GET_Y_LPARAM( lParam );
    CUIDrawTool::ScreenToFrame( GetHwnd(), ptCursor );

    LRESULT hitCode2 = HandNcHitTest( ptCursor );

    if ( HTNOWHERE != hitCode2 )
    {
        return hitCode2;
    }

    if ( hitCode == HTCLOSE || hitCode == HTMAXBUTTON || hitCode == HTMINBUTTON || hitCode == HTHELP /*|| hitCode == HTMENU*/ )
        return ( LRESULT )HTCAPTION;

    if ( ( hitCode == HTVSCROLL || hitCode == HTHSCROLL ) /*&& !IsFlatScrollBarInitialized()*/ )
        return ( LRESULT )HTCLIENT;

    return hitCode;
}

LRESULT CUIFrame::HandNcHitTest( const POINT& pt )
{
    CUICaptionButton* pCapBtnHot = HitTestButton( pt );

    if ( NULL != pCapBtnHot )
    {
        return pCapBtnHot->GetHitCode();
    }

    return HTNOWHERE;
}

LRESULT CUIFrame::OnNcLButtonDown( WPARAM wParam, LPARAM lParam )
{
    POINT ptCursor;
    ptCursor.x = GET_X_LPARAM( lParam );
    ptCursor.y = GET_Y_LPARAM( lParam );
    CUIDrawTool::ScreenToFrame( GetHwnd(), ptCursor );

    CUICaptionButton* pHot = HitTestButton( ptCursor );

    if ( NULL != pHot )
    {
        pHot->SetPressed( TRUE );
        InvalidCapBtns();
        m_pPressCapBtn = pHot;
    }

    return 0;
}

LRESULT CUIFrame::OnNCLButtonUp( WPARAM wParam, LPARAM lParam )
{
    POINT ptCursor;
    ptCursor.x = GET_X_LPARAM( lParam );
    ptCursor.y = GET_Y_LPARAM( lParam );
    CUIDrawTool::ScreenToFrame( GetHwnd(), ptCursor );

    CUICaptionButton* pHot = HitTestButton( ptCursor );

    if ( NULL != m_pPressCapBtn )
    {
        m_pPressCapBtn->SetPressed( FALSE );
        InvalidCapBtns();

        if ( m_pPressCapBtn == pHot && NULL != pHot )
        {
            SendMessage( GetHwnd(), pHot->GetID(), wParam, lParam );
        }

        m_pPressCapBtn = NULL;
    }

    return 0;
}

LRESULT CUIFrame::OnNcActive( WPARAM wParam, LPARAM lParam )
{
    WORD fActive = LOWORD( wParam );
    m_bFrameActive = fActive;
    int iActive = ( fActive == WA_INACTIVE ? NC_NOACTIVE : NC_ACTIVE );
    m_pFrameCaption->SetCurStatus( iActive );
    m_pFrameLeft->SetCurStatus( iActive );
    m_pFrameRight->SetCurStatus( iActive );
    m_pFrameBottom->SetCurStatus( iActive );

    OnNcPaint();
    return TRUE;
}

LRESULT CUIFrame::OnSize( WPARAM wParam, LPARAM lParam )
{
    RECT rcClient, rcWnd;
    ::GetClientRect( GetHwnd(), &rcClient );
    ::GetWindowRect( GetHwnd(), &rcWnd );

    m_pFrameCaption->SetSize( rcWnd.right - rcWnd.left, m_iFrameBorderHeight + m_iFrameHeight + m_iFrameCaptionHeight );

    m_pFrameLeft->SetPosition( 0, m_iFrameBorderHeight + m_iFrameHeight + m_iFrameCaptionHeight );
    m_pFrameLeft->SetSize( m_iFrameBorderWidth + m_iFrameWidth, rcWnd.bottom - rcWnd.top - m_iFrameHeight - m_iFrameBorderHeight );

    m_pFrameRight->SetPosition( rcWnd.right - rcWnd.left - m_iFrameBorderWidth - m_iFrameWidth, m_iFrameBorderHeight + m_iFrameHeight + m_iFrameCaptionHeight );
    m_pFrameRight->SetSize( m_iFrameBorderWidth + m_iFrameWidth, rcWnd.bottom - rcWnd.top - m_iFrameHeight - m_iFrameBorderHeight );

    m_pFrameBottom->SetPosition( 0, rcWnd.bottom - rcWnd.top - m_iFrameBorderHeight - m_iFrameHeight );
    m_pFrameBottom->SetSize( rcWnd.right - rcWnd.left, m_iFrameBorderHeight + m_iFrameHeight );

    CUICaptionButton* pClose = m_vecCapBtn[0];

    if ( NULL != pClose )
    {
        pClose->SetPosition( rcWnd.right - rcWnd.left - pClose->GetSize().cx - 5, 10 );
    }

    CUICaptionButton* pMax = m_vecCapBtn[1];

    if ( NULL != pMax )
    {
        pMax->SetPosition( pClose->GetBorder().left - pMax->GetSize().cx, 10 );
    }

    CUICaptionButton* pMin = m_vecCapBtn[2];

    if ( NULL != pMin )
    {
        pMin->SetPosition( pMax->GetBorder().left - pMin->GetSize().cx, 10 );
    }

//	InvalidateRect(GetHwnd(),NULL,TRUE);
    return 0;
}

LRESULT CUIFrame::OnEraseBkgnd( WPARAM wParam, LPARAM lParam )
{
    HDC hDC = ( HDC )wParam;
    RECT rcClient;
    ::GetClientRect( GetHwnd(), &rcClient );
    CUIMemDC MemDC( hDC, rcClient );
    m_pFrameBK->SetPosition( 0, 0 );
    m_pFrameBK->SetSize( rcClient.right - rcClient.left, rcClient.bottom - rcClient.top );
    m_pFrameBK->Draw( MemDC.GetDC() );
    return TRUE;
}

LRESULT CUIFrame::OnNcCalcSize( WPARAM wParam, LPARAM lParam )
{
    BOOL bCacl = ( BOOL )wParam;

    if ( bCacl )
    {
        NCCALCSIZE_PARAMS* pSize = ( NCCALCSIZE_PARAMS* )lParam;
        RECT& rcClient = pSize->rgrc[0];
        rcClient.top += m_iFrameCaptionHeight - m_iOldCapHeight/*-m_iFrameBorderHeight-m_iFrameHeight*/;
    }

    return 0;
}

LRESULT CUIFrame::OnInitMenuPopup( WPARAM wParam, LPARAM lParam )
{
    HWND hMenuWnd = FindWindow( _T( "#32768" ), NULL );

    if ( IsWindow( hMenuWnd ) )
    {
        m_pPopupMenu = new CUIMenu( GetHwnd(), hMenuWnd );
        m_pPopupMenu->OnInitMenuPopup( wParam, lParam );
    }

    return 0;
}

LRESULT CUIFrame::OnMeasureItem( WPARAM wParam, LPARAM lParam )
{
    MEASUREITEMSTRUCT* pMenuStruct = ( MEASUREITEMSTRUCT* )lParam;

    if ( ODT_MENU != pMenuStruct->CtlType )
    {
        return 0;
    }

    return m_pPopupMenu->OnMeasureItem( wParam, lParam );
}

LRESULT CUIFrame::OnDrawItem( WPARAM wParam, LPARAM lParam )
{
    DRAWITEMSTRUCT* pDrawStruct = ( DRAWITEMSTRUCT* )lParam;

    if ( ODT_MENU != pDrawStruct->CtlType )
    {
        return 0;
    }

    return m_pPopupMenu->OnDrawItem( wParam, lParam );
}

LRESULT CUIFrame::OnWindowPosChanging( WPARAM wParam, LPARAM lParam )
{
    static BOOL bReCalc = FALSE;

    if ( !bReCalc )
    {
        WINDOWPOS* pos = ( WINDOWPOS* )lParam;

        if ( IsWindow( pos->hwnd ) )
        {
            pos->cy += m_iFrameCaptionHeight - m_iOldCapHeight;
            bReCalc = TRUE;
        }
    }

    return 0;
}

CUICaptionButton* CUIFrame::HitTestButton( const POINT& pt )
{
    vector<CUICaptionButton*>::const_iterator cit = m_vecCapBtn.begin();

    for ( cit; cit != m_vecCapBtn.end(); cit++ )
    {
        CUICaptionButton* pCapbtn = *cit;

        if ( ::PtInRect( &pCapbtn->GetBorder(), pt ) )
        {
            return pCapbtn;
        }
    }

    return NULL;
}

LRESULT CUIFrame::OnNcMouseMove( WPARAM wParam, LPARAM lParam )
{
    LRESULT bRet = TRUE;
    POINT ptCursor;
    ptCursor.x = GET_X_LPARAM( lParam );
    ptCursor.y = GET_Y_LPARAM( lParam );
    CUIDrawTool::ScreenToFrame( GetHwnd(), ptCursor );

    CUICaptionButton* pHot = HitTestButton( ptCursor );

    if ( pHot != m_pHotCapBtn )
    {
        if ( NULL != pHot )
        {
            pHot->SetHovered( TRUE );
        }

        if ( NULL != m_pHotCapBtn )
        {
            m_pHotCapBtn->SetHovered( FALSE );
        }

        m_pHotCapBtn = pHot;
        InvalidCapBtns();
    }

    return bRet;
    return bRet;
}

void CUIFrame::InvalidCapBtns()
{
    CUIWindowDC dc( GetHwnd() );
    vector<CUICaptionButton*>::const_iterator cit = m_vecCapBtn.begin();

    for ( cit; cit != m_vecCapBtn.end(); cit++ )
    {
        CUICaptionButton* pCapbtn = *cit;
        pCapbtn->Draw( dc.GetDC() );
    }
}

LRESULT CUIFrame::OnNcMouseLeave( WPARAM wParam, LPARAM lParam )
{
    return OnNcMouseMove( -1, -1 );
}

LRESULT CUIFrame::ProcessUIMsg( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    switch ( uMsg )
    {
    case 174:
        return TRUE;

    case SYS_BTN_CLOSE:
    {
        SendMessage( GetHwnd(), WM_CLOSE, 0, 0 );
    }
    break;

    case SYS_BTN_RESTORE:
    {
        if ( IsZoomed( GetHwnd() ) )
        {
            ::SendMessage( GetHwnd(),   WM_SYSCOMMAND,   SC_RESTORE,   0 );
        }
        else
            ::SendMessage( GetHwnd(),   WM_SYSCOMMAND,   SC_MAXIMIZE,   0 );
    }
    break;

    case SYS_BTN_MIN:
    {
        ::SendMessage( GetHwnd(),   WM_SYSCOMMAND,   SC_MINIMIZE,   0 );
    }
    break;

    case WM_INITMENUPOPUP:
    {
        return OnInitMenuPopup( wParam, lParam );
    }

    case WM_UNINITMENUPOPUP:
    {
        if ( NULL != m_pPopupMenu )
        {
            delete m_pPopupMenu;
            m_pPopupMenu = NULL;
        }

        return 0;
    }

    case WM_MEASUREITEM:
    {
        return OnMeasureItem( wParam, lParam );
    }

    case WM_DRAWITEM:
    {
        return OnDrawItem( wParam, lParam );
    }

    case WM_SIZE:
    {
        LRESULT lRet = CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );
        return OnSize( wParam, lParam );
    }

    case WM_NCACTIVATE:
    case WM_ACTIVATEAPP:
    {
        return OnNcActive( wParam, lParam );
    }

    case WM_NCPAINT:
    {
        return OnNcPaint();
    }

// 	case WM_ERASEBKGND:
// 		{
// 			if (NULL!=m_pFrameBK)
// 			{
// 				return OnEraseBkgnd(wParam,lParam);
// 			}
// 			break;
// 		}
    case WM_NCLBUTTONDOWN:
    {
        LRESULT lRet = CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );
        return OnNcLButtonDown( wParam, lParam );
    }
    break;

    case WM_NCLBUTTONUP:
    {
        LRESULT lRet = CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );
        return OnNCLButtonUp( wParam, lParam );
    }

    case WM_NCHITTEST:
    {
        LRESULT lRet = CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );
        return OnNcHitTest( wParam, lParam, lRet );
    }

    case WM_NCMOUSEMOVE:
    {
        CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );

        return OnNcMouseMove( wParam, lParam );
    }

    case WM_NCMOUSELEAVE:
    {
        CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );
        return OnNcMouseLeave( wParam, lParam );
    }

    case WM_NCCALCSIZE:
    {
        CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );
        return OnNcCalcSize( wParam, lParam );
    }

    case WM_WINDOWPOSCHANGING:
    {
        CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );
        return OnWindowPosChanging( wParam, lParam );
    }

// 	case WM_WINDOWPOSCHANGED:
// 		{
// 			RECT rcClient={0};
// 			::GetClientRect(GetHwnd(),&rcClient);
// 			InvalidateRect(GetHwnd(),&rcClient,TRUE);
// 		}
// 		break;
    default:
        break;
    }

    return CUIWindowBase::ProcessUIMsg( uMsg, wParam, lParam );
}